#pragma once
#include <windows.h>
#include <tchar.h>
const int MEMORY_STACKS = 20;
enum FunctionType{
	FunUnknown = 0,
	FunHeapAlloc,
	FunHeapFree
};
#define BUF_SIZE 200
struct LogMessage{
	DWORD			nProcessId;
    FILETIME		ftOccurance;
	FunctionType	function;
	void *			memAlloc;
	size_t			size;
	HANDLE			hHeap;
	struct Stackinfo{
		DWORD_PTR stack[MEMORY_STACKS];
	};
	Stackinfo	callStack;
};
const TCHAR * const TRACE_PIPE_NAME = _T("\\\\.\\pipe\\memtrace");

inline bool operator ==(const LogMessage::Stackinfo &left, const LogMessage::Stackinfo &right)
{
	for (int i = 0; i<MEMORY_STACKS; ++i){
		if(left.stack[i] != right.stack[i]){return false;}
	}
	return true;
}
class StackInfoHash{
public:
	size_t operator()(const LogMessage::Stackinfo stack) const
	{
		size_t ret = 0;
		for (int i = 0; i<MEMORY_STACKS; ++i){
			if (stack.stack[i] == 0) {break;}
			ret += stack.stack[i];
		}
		return ret;
	}
};